This repository has been archived by the owner on Oct 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
RequestUserLogin.java
106 lines (85 loc) · 3.34 KB
/
RequestUserLogin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* This is the source code of iGap for Android
* It is licensed under GNU AGPL v3.0
* You should have received a copy of the license in this archive (see LICENSE).
* Copyright © 2017 , iGap - www.iGap.net
* iGap Messenger | Free, Fast and Secure instant messaging application
* The idea of the RooyeKhat Media Company - www.RooyeKhat.co
* All rights reserved.
*/
package net.iGap.request;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import net.iGap.helper.HelperString;
import net.iGap.proto.ProtoGlobal;
import net.iGap.proto.ProtoRequest;
import net.iGap.proto.ProtoUserLogin;
import java.util.Locale;
import static net.iGap.G.context;
public class RequestUserLogin {
private int AppBuildVersion;
private String AppVersion;
private String Device;
private String Language;
public void userLogin(String token) {
infoApp();
ProtoUserLogin.UserLogin.Builder userLogin = ProtoUserLogin.UserLogin.newBuilder();
userLogin.setRequest(ProtoRequest.Request.newBuilder().setId(HelperString.generateKey()));
userLogin.setToken(token);
userLogin.setAppName("iGap Android");
userLogin.setAppId(2);
userLogin.setAppBuildVersion(AppBuildVersion);
userLogin.setAppVersion(AppVersion);
userLogin.setPlatform(ProtoGlobal.Platform.ANDROID);
userLogin.setPlatformVersion(Integer.toString(android.os.Build.VERSION.SDK_INT));//api number
userLogin.setDevice(typeMobile()); //
userLogin.setDeviceName(Device);
userLogin.setLanguage(typeLanguage());
RequestWrapper requestWrapper = new RequestWrapper(102, userLogin);
try {
RequestQueue.sendRequest(requestWrapper);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
private void infoApp() {
PackageInfo pInfo = null;
try {
pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (pInfo != null) {
AppVersion = pInfo.versionName;
AppBuildVersion = pInfo.versionCode;
}
Device = Build.BRAND;
Language = Locale.getDefault().getDisplayLanguage();
}
private ProtoGlobal.Language typeLanguage() {
Language = Locale.getDefault().getDisplayLanguage();
if (Language.equals("English")) {
return ProtoGlobal.Language.FA_IR;
} else {
return ProtoGlobal.Language.EN_US;
}
}
private ProtoGlobal.Device typeMobile() {
DisplayMetrics metrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(metrics);
float yInches = metrics.heightPixels / metrics.ydpi;
float xInches = metrics.widthPixels / metrics.xdpi;
double diagonalInches = Math.sqrt(xInches * xInches + yInches * yInches);
if (diagonalInches >= 6.5) {
return ProtoGlobal.Device.TABLET;
} else {
// smaller device
return ProtoGlobal.Device.MOBILE;
}
}
}