Skip to content

Commit c0ab00c

Browse files
committed
Bump QPython OH for Huawei 3.0.0
1 parent c66a45b commit c0ab00c

File tree

22 files changed

+2649
-2
lines changed

22 files changed

+2649
-2
lines changed

qpython/build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ android {
106106
}
107107

108108
op {
109+
// resValue "string", "app_name", "QpythonL"
110+
applicationId "com.hipipal.qpyplus"
111+
}
112+
oh {
109113
// resValue "string", "app_name", "QpythonL"
110114
applicationId "com.hipipal.qpyplus"
111115
}
@@ -196,6 +200,15 @@ dependencies {
196200
exclude group: 'com.android.support:support-v4'
197201
}
198202

203+
ohApi('com.tencent.mm.opensdk:wechat-sdk-android-with-mta:1.4.0') {
204+
exclude group: 'com.android.support:support-v4'
205+
}
206+
// 友盟统计
207+
ohApi('com.umeng.analytics:analytics:6.1.2') {
208+
exclude group: 'com.android.support:support-v4'
209+
}
210+
211+
199212
api 'com.youth.banner:banner:1.4.10'
200213
}
201214

qpython/src/oh/AndroidManifest.xml

Lines changed: 408 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
package org.qpython.qpy.main.activity;
2+
3+
import android.content.ActivityNotFoundException;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.content.pm.PackageManager;
7+
import android.net.Uri;
8+
import android.os.Build;
9+
import android.os.Bundle;
10+
import android.os.Environment;
11+
import android.support.annotation.NonNull;
12+
import android.support.annotation.Nullable;
13+
import android.support.v4.app.ActivityCompat;
14+
import android.support.v4.content.ContextCompat;
15+
import android.support.v4.util.ArrayMap;
16+
import android.support.v7.app.AppCompatActivity;
17+
import android.text.TextUtils;
18+
import android.widget.Toast;
19+
20+
import com.quseit.util.NAction;
21+
import com.quseit.util.NUtil;
22+
import com.umeng.analytics.MobclickAgent;
23+
24+
import org.qpython.qpy.R;
25+
import org.qpython.qpy.console.ShellTermSession;
26+
import org.qpython.qpy.console.util.TermSettings;
27+
import org.qpython.qpy.main.server.gist.TokenManager;
28+
import org.renpy.android.ResourceManager;
29+
30+
import java.io.File;
31+
import java.io.FileInputStream;
32+
import java.io.FileNotFoundException;
33+
import java.io.FileOutputStream;
34+
import java.io.IOException;
35+
import java.io.InputStream;
36+
import java.io.OutputStream;
37+
import java.text.MessageFormat;
38+
import java.util.ArrayList;
39+
import java.util.Map;
40+
41+
42+
public class BaseActivity extends AppCompatActivity {
43+
// QPython interfaces
44+
private static final int SCRIPT_CONSOLE_CODE = 1237;
45+
private static final int PID_INIT_VALUE = -1;
46+
private static final int DEFAULT_BUFFER_SIZE = 8192;
47+
private static final int LOG_NOTIFICATION_ID = (int) System.currentTimeMillis();
48+
private ArrayList<String> mArguments = new ArrayList<>();
49+
private InputStream mIn;
50+
private OutputStream mOut;
51+
private Map<Integer, PermissionAction> mActionMap = new ArrayMap<>();
52+
private TermSettings mSettings;
53+
private ShellTermSession session;
54+
55+
private boolean permissionGrant = true;
56+
57+
protected static ShellTermSession createTermSession(Context context, TermSettings settings, String initialCommand, String path) {
58+
ShellTermSession session = null;
59+
try {
60+
session = new ShellTermSession(context, settings, initialCommand, path);
61+
session.setProcessExitMessage(context.getString(R.string.process_exit_message));
62+
63+
} catch (IOException e) {
64+
e.printStackTrace();
65+
}
66+
67+
return session;
68+
}
69+
70+
protected void toast(String content) {
71+
Toast.makeText(this, content, Toast.LENGTH_SHORT).show();
72+
}
73+
74+
@Override
75+
protected void onResume() {
76+
super.onResume();
77+
MobclickAgent.onPageStart(this.getLocalClassName());
78+
MobclickAgent.onResume(this);
79+
}
80+
81+
@Override
82+
protected void onCreate(@Nullable Bundle savedInstanceState) {
83+
super.onCreate(savedInstanceState);
84+
MobclickAgent.setDebugMode(true);
85+
MobclickAgent.openActivityDurationTrack(false);
86+
MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);
87+
}
88+
89+
@Override
90+
protected void onPause() {
91+
super.onPause();
92+
MobclickAgent.onPageEnd(this.getLocalClassName());
93+
MobclickAgent.onPause(this);
94+
}
95+
96+
@Override
97+
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
98+
PermissionAction action = mActionMap.get(requestCode);
99+
if (action != null) {
100+
if (grantResults.length > 0 && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
101+
action.onGrant();
102+
} else {
103+
action.onDeny();
104+
}
105+
106+
}
107+
mActionMap.remove(action);
108+
}
109+
110+
111+
public final void checkPermissionDo(String[] permissions, PermissionAction action) {
112+
if (Build.VERSION.SDK_INT >= 23) {
113+
boolean granted = true;
114+
for (String permission : permissions) {
115+
int checkPermission = ContextCompat.checkSelfPermission(this, permission);
116+
granted = checkPermission == PackageManager.PERMISSION_GRANTED;
117+
}
118+
if (!granted) {
119+
int code = permissions.hashCode() & 0xffff;
120+
mActionMap.put(code, action);
121+
ActivityCompat.requestPermissions(this, permissions, code);
122+
} else {
123+
action.onGrant();
124+
}
125+
} else {
126+
action.onGrant();
127+
}
128+
}
129+
130+
131+
// feedback
132+
public void onFeedback(String feedback) {
133+
134+
String app = getString(R.string.app_name);
135+
int ver = NUtil.getVersinoCode(getApplicationContext());
136+
String subject = MessageFormat.format(getString(com.quseit.android.R.string.feeback_email_title), app, ver, Build.PRODUCT);
137+
138+
String lastError = "";
139+
String code = NAction.getCode(getApplicationContext());
140+
File log = new File(Environment.getExternalStorageDirectory() + "/" + code + "_last_err.log");
141+
if (log.exists()) {
142+
lastError = com.quseit.util.FileHelper.getFileContents(log.getAbsolutePath());
143+
}
144+
145+
String body = MessageFormat.format(getString(R.string.feedback_email_body), Build.PRODUCT,
146+
Build.VERSION.RELEASE, Build.VERSION.SDK, lastError, feedback);
147+
148+
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + getString(R.string.ui_feedback_mail)));
149+
150+
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
151+
intent.putExtra(Intent.EXTRA_TEXT, session == null ? body : session.getTranscriptText().trim());
152+
try {
153+
startActivity(Intent.createChooser(intent,
154+
getString(R.string.email_transcript_chooser_title)));
155+
} catch (ActivityNotFoundException e) {
156+
Toast.makeText(this,
157+
R.string.email_transcript_no_email_activity_found,
158+
Toast.LENGTH_LONG)
159+
.show();
160+
}
161+
}
162+
163+
protected boolean checkExpired(final String resource, String filesDir, String tag) {
164+
ResourceManager resourceManager = new ResourceManager(this);
165+
166+
String data_version = resourceManager.getString(resource + "_version");
167+
String disk_version = "0";
168+
169+
// If no version, no unpacking is necessary.
170+
if (data_version == null) {
171+
return false;
172+
}
173+
174+
// Check the current disk version, if any.
175+
String disk_version_fn = filesDir + "/lib/" + tag + "_" + resource + ".version";
176+
177+
try {
178+
byte buf[] = new byte[64];
179+
InputStream is = new FileInputStream(disk_version_fn);
180+
int len = is.read(buf);
181+
disk_version = new String(buf, 0, len);
182+
is.close();
183+
} catch (Exception e) {
184+
185+
disk_version = "0";
186+
//Mint.logException(e);
187+
188+
}
189+
190+
//LogUtil.d(TAG, "data_version:"+Math.round(Double.parseDouble(data_version))+"-disk_version:"+Math.round(Double.parseDouble(disk_version))+"-RET:"+(int)(Double.parseDouble(data_version)-Double.parseDouble(disk_version)));
191+
if ((int) (Double.parseDouble(data_version) - Double.parseDouble(disk_version)) > 0 || disk_version.equals("0")) {
192+
try {
193+
FileOutputStream os = new FileOutputStream(disk_version_fn);
194+
try {
195+
os.write(data_version.getBytes());
196+
os.close();
197+
198+
} catch (IOException e) {
199+
e.printStackTrace();
200+
//Mint.logException(e);
201+
202+
}
203+
204+
} catch (FileNotFoundException e) {
205+
e.printStackTrace();
206+
//Mint.logException(e);
207+
208+
}
209+
210+
211+
return true;
212+
} else {
213+
return false;
214+
}
215+
}
216+
217+
public interface PermissionAction {
218+
void onGrant();
219+
220+
void onDeny();
221+
}
222+
223+
public void ifLogin(Login afterLogin) {
224+
if (!TextUtils.isEmpty(TokenManager.getToken())) {
225+
afterLogin.process();
226+
} else {
227+
Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show();
228+
}
229+
}
230+
231+
public interface Login {
232+
void process();
233+
}
234+
235+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package org.qpython.qpy.main.activity;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.databinding.DataBindingUtil;
6+
import android.os.Bundle;
7+
import android.support.annotation.Nullable;
8+
import android.text.TextUtils;
9+
import android.view.View;
10+
import android.widget.Toast;
11+
12+
//import com.hipipal.qpyplus.wxapi.PaymentStatus;
13+
//import com.hipipal.qpyplus.wxapi.WXAPIManager;
14+
//import com.hipipal.qpyplus.wxapi.WeixinPay;
15+
import com.quseit.util.VeDate;
16+
17+
import org.greenrobot.eventbus.Subscribe;
18+
import org.json.JSONException;
19+
import org.json.JSONObject;
20+
import org.qpython.qpy.R;
21+
import org.qpython.qpy.databinding.ActivityFundingPurchaseBinding;
22+
import org.qpython.qpy.main.app.App;
23+
import org.qpython.qpy.utils.UpdateHelper;
24+
25+
import rx.Observer;
26+
27+
/**
28+
* Created by Hmei
29+
* 1/30/18.
30+
*/
31+
32+
public class FundingPurchaseActivity extends PayActivity {
33+
private static final String FUNDING_COUNT = "fundingCount";
34+
private ActivityFundingPurchaseBinding binding;
35+
36+
@Override
37+
protected void onCreate(@Nullable Bundle savedInstanceState) {
38+
super.onCreate(savedInstanceState);
39+
binding = DataBindingUtil.setContentView(this, R.layout.activity_funding_purchase);
40+
initView();
41+
String[] count = getResources().getStringArray(R.array.funding_count_divider);
42+
String[] prices = getResources().getStringArray(R.array.wechat_funding_price);
43+
String price = null;
44+
int fundingCount = getIntent().getIntExtra(FUNDING_COUNT, 0);
45+
for (int i = 0; i < count.length; i++) {
46+
if ((Integer.parseInt(count[i]) - fundingCount) > 0) {
47+
price = prices[i];
48+
break;
49+
}
50+
}
51+
if (TextUtils.isEmpty(price)) price = prices[prices.length - 1];
52+
binding.price.setText(getString(R.string.rmb, price));
53+
String finalPrice = price;
54+
// binding.price.setOnClickListener(v -> payUtil.purchase(finalPrice, getIntent().getStringExtra(ARTICLE_ID), new Observer<WeixinPay>() {
55+
// @Override
56+
// public void onCompleted() {
57+
// binding.pb.setVisibility(View.GONE);
58+
// // 统计赞赏数据
59+
// JSONObject jsonObject = new JSONObject();
60+
// try {
61+
// jsonObject.put("type", finalPrice);
62+
// jsonObject.put("time", VeDate.getStringDateHourAsInt());
63+
// int percent = getIntent().getIntExtra(FUNDING_COUNT, 0);
64+
// String[] fundingCount = getResources().getStringArray(R.array.funding_count_divider);
65+
// jsonObject.put("crowdfunding",
66+
// percent > (Integer.parseInt(fundingCount[1]) / Integer.parseInt(fundingCount[2])) ? 3 :
67+
// percent > (Integer.parseInt(fundingCount[0]) / Integer.parseInt(fundingCount[1])) ? 2 : 1);//0 非众筹/ 1: 0-100 /2: 100-500/3 500-2000
68+
// jsonObject.put("articleId", getIntent().getStringExtra(ARTICLE_ID));
69+
// if (App.getUser() != null) {
70+
// jsonObject.put("account", App.getUser().getEmail());
71+
// }
72+
// } catch (JSONException e) {
73+
// e.printStackTrace();
74+
// }
75+
// UpdateHelper.submitIAPLog(FundingPurchaseActivity.this, mOrderNo, App.getGson().toJson(jsonObject));
76+
// }
77+
//
78+
// @Override
79+
// public void onError(Throwable e) {
80+
// Toast.makeText(FundingPurchaseActivity.this, R.string.conn_error, Toast.LENGTH_SHORT).show();
81+
// binding.pb.setVisibility(View.GONE);
82+
// }
83+
//
84+
// @Override
85+
// public void onNext(WeixinPay weixinPay) {
86+
// WXAPIManager.wxPayReq(weixinPay);
87+
// mOrderNo = weixinPay.out_trade_no;
88+
// }
89+
// }));
90+
}
91+
92+
public static void startSupport(Context context, String articleId, int fundingPercent) {
93+
Intent starter = new Intent(context, FundingPurchaseActivity.class);
94+
starter.putExtra(ARTICLE_ID, articleId);
95+
starter.putExtra(FUNDING_COUNT, fundingPercent);
96+
context.startActivity(starter);
97+
}
98+
99+
private void initView() {
100+
setSupportActionBar(binding.lt.toolbar);
101+
binding.lt.toolbar.setNavigationIcon(R.drawable.ic_back);
102+
binding.lt.toolbar.setNavigationOnClickListener(v -> finish());
103+
setTitle(R.string.reward);
104+
binding.tvThanks.setVisibility(View.VISIBLE);
105+
binding.price.setVisibility(View.VISIBLE);
106+
}
107+
}

0 commit comments

Comments
 (0)