Browse Source

初步搭建登录界面 优化 登录功能实现

developer
lh 8 years ago
parent
commit
7a14b58120
17 changed files with 591 additions and 11 deletions
  1. +1
    -0
      app/src/main/AndroidManifest.xml
  2. +6
    -6
      app/src/main/java/com/qhclh/ytzh/home/MainActivity.java
  3. +123
    -0
      app/src/main/java/com/qhclh/ytzh/login/LoginActivity.java
  4. +2
    -1
      app/src/main/java/com/qhclh/ytzh/splash/SplashActivity.java
  5. +44
    -0
      app/src/main/java/com/qhclh/ytzh/utils/ActivityUtil.java
  6. +321
    -0
      app/src/main/java/com/qhclh/ytzh/utils/HdHttpUtil.java
  7. BIN
      app/src/main/res/drawable-xhdpi/gongzuo1_3x.png
  8. BIN
      app/src/main/res/drawable-xhdpi/gongzuo_3x.png
  9. BIN
      app/src/main/res/drawable-xhdpi/shouye1_3x.png
  10. BIN
      app/src/main/res/drawable-xhdpi/shouye_3x.png
  11. BIN
      app/src/main/res/drawable-xhdpi/wode1_3x.png
  12. BIN
      app/src/main/res/drawable-xhdpi/wode_3x.png
  13. +84
    -0
      app/src/main/res/layout/act_login.xml
  14. +1
    -0
      app/src/main/res/values/colors.xml
  15. +3
    -3
      app/src/main/res/values/dimens.xml
  16. +3
    -0
      app/src/main/res/values/strings.xml
  17. +3
    -1
      app/src/main/res/values/styles.xml

+ 1
- 0
app/src/main/AndroidManifest.xml View File

@ -26,6 +26,7 @@
</intent-filter>
</activity>
<activity android:name=".home.MainActivity"/>
<activity android:name=".login.LoginActivity"/>
<!--友盟 -->


+ 6
- 6
app/src/main/java/com/qhclh/ytzh/home/MainActivity.java View File

@ -106,20 +106,20 @@ public class MainActivity extends BaseActivity {
clearAllTabState();
switch (tabPosition) {
case TAB_POSITION_INDEX: {
// iv_index.setImageResource(R.drawable.ghs12x);
iv_index.setImageResource(R.drawable.shouye_3x);
tv_index.setTextColor(getResources().getColor(R.color.green029737));
mTvToolbarTitle.setText(R.string.index);
break;
}
case TAB_POSITION_WORK: {
// iv_work.setImageResource(R.drawable.gwc12x);
iv_work.setImageResource(R.drawable.gongzuo_3x);
tv_work.setTextColor(getResources().getColor(R.color.green029737));
mTvToolbarTitle.setText(R.string.work);
break;
}
case TAB_POSITION_ME: {
// iv_me.setImageResource(R.drawable.dd12x);
iv_me.setImageResource(R.drawable.wode_3x);
tv_me.setTextColor(getResources().getColor(R.color.green029737));
mTvToolbarTitle.setText(R.string.me);
break;
@ -130,14 +130,14 @@ public class MainActivity extends BaseActivity {
private void clearAllTabState() {
///< 首页
// iv_index.setImageResource(R.drawable.ghs2x);
iv_index.setImageResource(R.drawable.shouye1_3x);
tv_index.setTextColor(getResources().getColor(R.color.grey888888));
///< 工作
// iv_work.setImageResource(R.drawable.gwc2x);
iv_work.setImageResource(R.drawable.gongzuo1_3x);
tv_work.setTextColor(getResources().getColor(R.color.grey888888));
///< 我的
// iv_me.setImageResource(R.drawable.dd2x);
iv_me.setImageResource(R.drawable.wode1_3x);
tv_me.setTextColor(getResources().getColor(R.color.grey888888));
}


+ 123
- 0
app/src/main/java/com/qhclh/ytzh/login/LoginActivity.java View File

@ -0,0 +1,123 @@
package com.qhclh.ytzh.login;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.qhclh.ytzh.R;
import com.qhclh.ytzh.base.BaseActivity;
import com.qhclh.ytzh.configs.ConfigUtil;
import com.qhclh.ytzh.configs.LoginUserConfig;
import com.qhclh.ytzh.configs.ServerConfig;
import com.qhclh.ytzh.home.MainActivity;
import com.qhclh.ytzh.home.MyApplication;
import com.qhclh.ytzh.tasks.ViewOnClickTask;
import com.qhclh.ytzh.utils.ActivityUtil;
import com.qhclh.ytzh.utils.DialogUtil;
import com.qhclh.ytzh.utils.HdHttpUtil;
import org.forks.jsonrpc.RpcFacade;
import butterknife.BindView;
import butterknife.OnClick;
/**
* Created by 青花瓷 on 2017/11/28.
*/
public class LoginActivity extends BaseActivity {
@BindView(R.id.login_username)
EditText login_username;
@BindView(R.id.login_psw)
EditText login_psw;
@BindView(R.id.login_sure)
Button login_sure;
private LoginUserConfig config = new LoginUserConfig(this);
private ServerConfig sconfig = new ServerConfig(this);
@Override
protected int setLayoutId() {
return R.layout.act_login;
}
@Override
protected void initView() {
loginOut.execute();
MyApplication.ClearLogin();
ConfigUtil.Fill(sconfig);
ConfigUtil.Fill(config);
login_username.setText(config.Username);
login_psw.setText(config.Password);
}
@Override
protected void initData() {
}
@Override
protected void initOper() {
}
@OnClick({R.id.login_sure})
public void onClick(View view) {
switch (view.getId()) {
case R.id.login_sure:
if (HdHttpUtil.isNetworkAvailable(LoginActivity.this)) {
loginTask.execute();
} else {
DialogUtil.AutoHiddenAlert(LoginActivity.this, "网络不可用");
}
break;
}
}
ViewOnClickTask loginOut = new ViewOnClickTask(this, "") {
@Override
public Object call() throws Exception {
RpcFacade.logout();
return null;
}
@Override
protected void successUI() {
}
};
ViewOnClickTask loginTask = new ViewOnClickTask(this, "登录中...") {
public Object call() throws Exception {
String username = login_username.getText().toString();
String password = login_psw.getText().toString();
config.Username = username;
config.Password = password;
RpcFacade.logout();
RpcFacade.login(username, password);
config.DisplayName = username;
ConfigUtil.Save(config);
return null;
}
@Override
protected void successUI() {
ConfigUtil.Fill(sconfig);
ActivityUtil.Go(LoginActivity.this, MainActivity.class);
}
};
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//按返回键程序进入后台运行不关闭程序
MyApplication.getInstance().exit();
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}

+ 2
- 1
app/src/main/java/com/qhclh/ytzh/splash/SplashActivity.java View File

@ -8,6 +8,7 @@ import android.widget.LinearLayout;
import com.qhclh.ytzh.R;
import com.qhclh.ytzh.base.BaseActivity;
import com.qhclh.ytzh.home.MainActivity;
import com.qhclh.ytzh.login.LoginActivity;
import butterknife.BindView;
@ -60,7 +61,7 @@ public class SplashActivity extends BaseActivity {
}
private void redirectTo() {
startActivity(new Intent(this, MainActivity.class));
startActivity(new Intent(this, LoginActivity.class));
finish();
}
}

+ 44
- 0
app/src/main/java/com/qhclh/ytzh/utils/ActivityUtil.java View File

@ -0,0 +1,44 @@
package com.qhclh.ytzh.utils;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class ActivityUtil {
public String GetText(Activity activity, int id) {
View view = activity.findViewById(id);
if (view instanceof EditText) {
return ((EditText) view).getText().toString();
}
return String.format("未支持得到类型%s的文本", view.getClass());
}
public static Button FindButton(Activity activity, int id) {
return (Button) activity.findViewById(id);
}
public static void Go(Context context, Class<?> class1) {
Intent intent = new Intent();
intent.setClass(context, class1);
context.startActivity(intent);
}
public static void Go(View arg0, Class<?> class1) {
Go(arg0.getContext(), class1);
}
@SuppressWarnings("unchecked")
public static <T extends View> T Find(Activity activity, int id) {
return (T) activity.findViewById(id);
}
public static void Finish(Activity activity, Intent data) {
activity.setResult(Activity.RESULT_OK, data);
activity.finish();
}
}

+ 321
- 0
app/src/main/java/com/qhclh/ytzh/utils/HdHttpUtil.java View File

@ -0,0 +1,321 @@
package com.qhclh.ytzh.utils;
import android.content.Context;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* Created by luanhui on 2016/7/8.
*/
public class HdHttpUtil {
public static final int NETWORK_OPERATOR_UNKOWN = 0;
public static final int NETWORK_OPERATOR_MOBILE = 1;
public static final int NETWORK_OPERATOR_UNICOM = 2;
public static final int NETWORK_OPERATOR_TELECOM = 3;
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
/**
* String is null
*
* @param src
* @return boolean
*/
public static boolean isEmptyString(String src) {
return src == null || src.trim().length() == 0;
}
/**
* Return if the device is connected to wifi.
*
* @return boolean
*/
public static boolean isWifi(Context context) {
try {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
return true;
}
} catch (Exception e) {
}
return false;
}
/**
* 判断WiFi是否打开
*
* @param context
* @return
*/
public static boolean isWifiEnabled(Context context) {
ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager mgrTel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return ((mgrConn.getActiveNetworkInfo() != null
&& mgrConn.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED)
|| mgrTel.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}
/**
* Return if the device is connected to the 3G net.
*
* @param context
* @return boolean
*/
public static boolean is3G(Context context) {
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int networkType = telephony.getNetworkType();
return networkType == TelephonyManager.NETWORK_TYPE_UMTS || networkType == TelephonyManager.NETWORK_TYPE_HSDPA
|| networkType == TelephonyManager.NETWORK_TYPE_EVDO_0
|| networkType == TelephonyManager.NETWORK_TYPE_EVDO_A
|| networkType == TelephonyManager.NETWORK_TYPE_LTE
|| networkType == TelephonyManager.NETWORK_TYPE_EVDO_B
|| networkType == TelephonyManager.NETWORK_TYPE_EHRPD
|| networkType == TelephonyManager.NETWORK_TYPE_HSUPA;
}
/**
* 判断当前网络是WiFi还是3G
*
* @param context
* @return
*/
public static boolean isWifiOr3G(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkINfo = cm.getActiveNetworkInfo();
if (networkINfo != null && networkINfo.getType() == ConnectivityManager.TYPE_WIFI) {
return true;
}
return false;
}
/**
* Return if the device is connected to the 2G net.
*
* @param context
* @return boolean
*/
public static boolean is2G(Context context) {
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int networkType = telephony.getNetworkType();
return networkType == TelephonyManager.NETWORK_TYPE_1xRTT || networkType == TelephonyManager.NETWORK_TYPE_CDMA
|| networkType == TelephonyManager.NETWORK_TYPE_EDGE
|| networkType == TelephonyManager.NETWORK_TYPE_IDEN
|| networkType == TelephonyManager.NETWORK_TYPE_GPRS;
}
/**
* 判断Gsp是否可用
*
* @param context
* @return
*/
public static boolean isGpsEnabled(Context context) {
LocationManager lm = ((LocationManager) context.getSystemService(Context.LOCATION_SERVICE));
List<String> accessibleProviders = lm.getProviders(true);
return accessibleProviders != null && accessibleProviders.size() > 0;
}
/**
* Return if the network is available for the device
*
* @return boolean
*/
public static boolean isNetAvailable(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo != null) {
return networkInfo.isAvailable();
}
return false;
}
/**
* 判断网络连接是否可用
*
* @param context
* @return
*/
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null) {
} else {
// 如果仅仅是用来判断网络连接
// 则可以使用 cm.getActiveNetworkInfo().isAvailable();
NetworkInfo[] info = cm.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
/**
* Return if the device is connected to mobile network.
*
* @return boolean
*/
public static boolean isMobile(Context context) {
try {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
return true;
}
} catch (Exception e) {
}
return false;
}
/**
* Return if the device is connected to wap network.
*
* @return boolean
*/
public static boolean isWap(String proxyhost) {
Pattern pattern = Pattern.compile("^[0]{0,1}10\\.[0]{1,3}\\.[0]{1,3}\\.172$", Pattern.MULTILINE);
boolean ret = false;
Matcher m = pattern.matcher(proxyhost);
if (m.find()) {
ret = true;
} else {
ret = false;
}
return ret;
}
/**
* return if proxy is used for connect to the network
*
* @return
*/
public static boolean isPorxyUsed(Context context) {
if (isWifi(context)) {
return false;
}
// 不管cmnet和cmwap都选择直连方式
if (readNetworkOperatorType(context) == NETWORK_OPERATOR_MOBILE) {
return false;
}
String proxyHost = android.net.Proxy.getDefaultHost();
if (isEmptyString(proxyHost)) {
return false;
}
return true;
}
/**
* read the network operator type
*/
public static int readNetworkOperatorType(Context context) {
TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String operator = telManager.getNetworkOperator();
// 飞行模式下 获取不到operator
if (isEmptyString(operator)) {
return NETWORK_OPERATOR_UNKOWN;
}
// 非中国运营商
String mcc = operator.substring(0, 3);
if (mcc == null || !mcc.equals("460")) {
return NETWORK_OPERATOR_UNKOWN;
}
// operator 由mcc + mnc组成 中国的mcc为460
// 这里取得mnc来判断是国内的哪个运营商
String mnc = operator.substring(3);
int mncIntVar = 0;
try {
mncIntVar = Integer.parseInt(mnc);
} catch (NumberFormatException e) {
}
switch (mncIntVar) {
case 0:
case 2:
case 7:
return NETWORK_OPERATOR_MOBILE;
case 1:
case 6:
return NETWORK_OPERATOR_UNICOM;
case 3:
case 5:
return NETWORK_OPERATOR_TELECOM;
default:
break;
}
return NETWORK_OPERATOR_UNKOWN;
}
/**
* gzip decompress
*
* @param is
* @param os
* @throws Exception
*/
public static void decompress(InputStream is, OutputStream os) throws Exception {
GZIPInputStream gin = new GZIPInputStream(is);
int count;
byte data[] = new byte[1024];
while ((count = gin.read(data, 0, 1024)) != -1) {
os.write(data, 0, count);
}
gin.close();
}
/**
* gzip compress
*
* @param is
* @param os
* @throws Exception
*/
public static void compress(InputStream is, OutputStream os) throws Exception {
GZIPOutputStream gos = new GZIPOutputStream(os);
int count;
byte data[] = new byte[1024];
while ((count = is.read(data, 0, 1024)) != -1) {
gos.write(data, 0, count);
}
gos.flush();
gos.finish();
gos.close();
}
public static byte[] compress(byte[] is) throws Exception {
ByteArrayInputStream tmpInput = new ByteArrayInputStream(is);
ByteArrayOutputStream tmpOutput = new ByteArrayOutputStream(1024);
HdHttpUtil.compress(tmpInput, tmpOutput);
return tmpOutput.toByteArray();
}
}

BIN
app/src/main/res/drawable-xhdpi/gongzuo1_3x.png View File

Before After
Width: 69  |  Height: 66  |  Size: 2.7 KiB

BIN
app/src/main/res/drawable-xhdpi/gongzuo_3x.png View File

Before After
Width: 70  |  Height: 67  |  Size: 3.3 KiB

BIN
app/src/main/res/drawable-xhdpi/shouye1_3x.png View File

Before After
Width: 66  |  Height: 68  |  Size: 2.5 KiB

BIN
app/src/main/res/drawable-xhdpi/shouye_3x.png View File

Before After
Width: 63  |  Height: 66  |  Size: 2.8 KiB

BIN
app/src/main/res/drawable-xhdpi/wode1_3x.png View File

Before After
Width: 66  |  Height: 69  |  Size: 2.4 KiB

BIN
app/src/main/res/drawable-xhdpi/wode_3x.png View File

Before After
Width: 64  |  Height: 68  |  Size: 3.0 KiB

+ 84
- 0
app/src/main/res/layout/act_login.xml View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/login_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/login_bg" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/dp_16">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/inputuername"
android:inputType="text"
android:maxLines="1"
android:paddingLeft="@dimen/dp_10"
android:textColor="@color/black"
android:textColorHint="@color/greycacaca"
android:textSize="@dimen/text_size_18" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/dp_16">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/login_psw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/inputpsw"
android:inputType="textPassword"
android:maxLines="1"
android:paddingLeft="@dimen/dp_10"
android:textColor="@color/black"
android:textColorHint="@color/greycacaca"
android:textSize="@dimen/text_size_18" />
</LinearLayout>
<Button
android:id="@+id/login_sure"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_16"
android:layout_marginRight="@dimen/dp_16"
android:layout_marginTop="@dimen/dp_20"
android:padding="@dimen/dp_12"
android:text="@string/login"
android:textColor="@color/white"
android:textSize="@dimen/text_size_26" />
</LinearLayout>

+ 1
- 0
app/src/main/res/values/colors.xml View File

@ -23,6 +23,7 @@
<color name="grey888888">#888888</color>
<color name="greyf4f4f4">#f4f4f4</color>
<color name="greydbdbdb">#dbdbdb</color>
<color name="greycacaca">#cacaca</color>
</resources>

+ 3
- 3
app/src/main/res/values/dimens.xml View File

@ -131,9 +131,9 @@
<dimen name="px_8">8px</dimen>
<dimen name="px_20">20px</dimen>
<dimen name="tab_text_size">@dimen/text_size_16</dimen>
<dimen name="tab_icon_height">30dp</dimen>
<dimen name="tab_icon_width">30dp</dimen>
<dimen name="tab_text_size">@dimen/text_size_12</dimen>
<dimen name="tab_icon_height">28dp</dimen>
<dimen name="tab_icon_width">28dp</dimen>
<dimen name="tab_layout_padding">8dp</dimen>
<!-- ************************************************************分割线************************************************************-->


+ 3
- 0
app/src/main/res/values/strings.xml View File

@ -4,4 +4,7 @@
<string name="work">工作</string>
<string name="me">我的</string>
<string name="back_exit_app">再按一次返回键退出应用</string>
<string name="inputuername">请输入用户名</string>
<string name="inputpsw">请输入密码</string>
<string name="login">登录</string>
</resources>

+ 3
- 1
app/src/main/res/values/styles.xml View File

@ -32,7 +32,8 @@
</style>
<style name="TabLayout">
<item name="android:padding">@dimen/tab_layout_padding</item>
<item name="android:paddingTop">@dimen/tab_layout_padding</item>
<item name="android:paddingBottom">@dimen/dp_3</item>
<item name="android:layout_height">match_parent</item>
<!--<item name="android:background">@drawable/selector_white2gray</item>-->
<item name="android:layout_width">0dp</item>
@ -48,6 +49,7 @@
<style name="TabText">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_marginTop">@dimen/dp_3</item>
<item name="android:textColor">@color/grey_767c82</item>
<item name="android:textSize">@dimen/tab_text_size</item>
</style>


Loading…
Cancel
Save