/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.example;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.KeyEvent;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactRootView;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.modules.core.PermissionAwareActivity;
import com.facebook.react.modules.core.PermissionListener;
import javax.annotation.Nullable;
/**
* Base Activity for React Native applications.
*/publicabstractclassMyReactActivityextendsFragmentActivityimplementsDefaultHardwareBackBtnHandler, PermissionAwareActivity {privatefinal ReactActivityDelegate mDelegate;
protectedMyReactActivity() {
mDelegate = createReactActivityDelegate();
}
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
* e.g. "MoviesApp"
*/protected @Nullable
String getMainComponentName() {
returnnull;
}
/**
* Called at construction time, override if you have a custom delegate implementation.
*/protected ReactActivityDelegate createReactActivityDelegate() {
returnnew ReactActivityDelegate(this, getMainComponentName());
}
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDelegate.onCreate(savedInstanceState);
}
@OverrideprotectedvoidonPause() {
super.onPause();
mDelegate.onPause();
}
@OverrideprotectedvoidonResume() {
super.onResume();
mDelegate.onResume();
}
@OverrideprotectedvoidonDestroy() {
super.onDestroy();
mDelegate.onDestroy();
}
@OverridepublicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
mDelegate.onActivityResult(requestCode, resultCode, data);
}
@OverridepublicbooleanonKeyUp(int keyCode, KeyEvent event) {
return mDelegate.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event);
}
@OverridepublicvoidonBackPressed() {
if (!mDelegate.onBackPressed()) {
super.onBackPressed();
}
}
@OverridepublicvoidinvokeDefaultOnBackPressed() {
super.onBackPressed();
}
@OverridepublicvoidonNewIntent(Intent intent) {
if (!mDelegate.onNewIntent(intent)) {
super.onNewIntent(intent);
}
}
@OverridepublicvoidrequestPermissions(
String[] permissions,
int requestCode,
PermissionListener listener) {
mDelegate.requestPermissions(permissions, requestCode, listener);
}
@OverridepublicvoidonRequestPermissionsResult(
int requestCode,
String[] permissions,
int[] grantResults) {
mDelegate.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
protectedfinal ReactNativeHost getReactNativeHost() {
return mDelegate.getReactNativeHost();
}
protectedfinal ReactInstanceManager getReactInstanceManager() {
return mDelegate.getReactInstanceManager();
}
protectedfinalvoidloadApp(String appKey) {
mDelegate.loadApp(appKey);
}
public ReactRootView getRootView() {
return mDelegate.getRootView();
}
}
ReactActivityDelegate.java:
// Copyright 2004-present Facebook. All Rights Reserved.package com.example;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.FragmentActivity;
import android.view.KeyEvent;
import android.widget.Toast;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactFragmentActivity;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactRootView;
import com.facebook.react.bridge.Callback;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.devsupport.DoubleTapReloadRecognizer;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.modules.core.PermissionListener;
import javax.annotation.Nullable;
/**
* Delegate class for {@link ReactActivity} and {@link ReactFragmentActivity}. You can subclass this
* to provide custom implementations for e.g. {@link #getReactNativeHost()}, if your Application
* class doesn't implement {@link ReactApplication}.
*/publicclassReactActivityDelegate {privatefinalint REQUEST_OVERLAY_PERMISSION_CODE = 1111;
privatestaticfinal String REDBOX_PERMISSION_GRANTED_MESSAGE =
"Overlay permissions have been granted.";
privatestaticfinal String REDBOX_PERMISSION_MESSAGE =
"Overlay permissions needs to be granted in order for react native apps to run in dev mode";
privatefinal @Nullable
Activity mActivity;
privatefinal @Nullable
FragmentActivity mFragmentActivity;
privatefinal @Nullable
String mMainComponentName;
private @Nullable
ReactRootView mReactRootView;
private @Nullable
DoubleTapReloadRecognizer mDoubleTapReloadRecognizer;
private @Nullable
PermissionListener mPermissionListener;
private @Nullable
Callback mPermissionsCallback;
publicReactActivityDelegate(Activity activity, @Nullable String mainComponentName) {
mActivity = activity;
mMainComponentName = mainComponentName;
mFragmentActivity = null;
}
publicReactActivityDelegate(
FragmentActivity fragmentActivity,
@Nullable String mainComponentName) {
mFragmentActivity = fragmentActivity;
mMainComponentName = mainComponentName;
mActivity = null;
}
protected @Nullable
Bundle getLaunchOptions() {
returnnull;
}
protected ReactRootView createRootView() {
returnnew ReactRootView(getContext());
}
/**
* Get the {@link ReactNativeHost} used by this app. By default, assumes
* {@link Activity#getApplication()} is an instance of {@link ReactApplication} and calls
* {@link ReactApplication#getReactNativeHost()}. Override this method if your application class
* does not implement {@code ReactApplication} or you simply have a different mechanism for
* storing a {@code ReactNativeHost}, e.g. as a static field somewhere.
*/protected ReactNativeHost getReactNativeHost() {
return ((ReactApplication) getPlainActivity().getApplication()).getReactNativeHost();
}
public ReactInstanceManager getReactInstanceManager() {
return getReactNativeHost().getReactInstanceManager();
}
protectedvoidonCreate(Bundle savedInstanceState) {
boolean needsOverlayPermission = false;
if (getReactNativeHost().getUseDeveloperSupport() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Get permission to show redbox in dev builds.if (!Settings.canDrawOverlays(getContext())) {
needsOverlayPermission = true;
Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getContext().getPackageName()));
FLog.w(ReactConstants.TAG, REDBOX_PERMISSION_MESSAGE);
Toast.makeText(getContext(), REDBOX_PERMISSION_MESSAGE, Toast.LENGTH_LONG).show();
((Activity) getContext()).startActivityForResult(serviceIntent, REQUEST_OVERLAY_PERMISSION_CODE);
}
}
if (mMainComponentName != null && !needsOverlayPermission) {
loadApp(mMainComponentName);
}
mDoubleTapReloadRecognizer = new DoubleTapReloadRecognizer();
}
protectedvoidloadApp(String appKey) {
if (mReactRootView != null) {
thrownew IllegalStateException("Cannot loadApp while app is already running.");
}
mReactRootView = createRootView();
mReactRootView.startReactApplication(
getReactNativeHost().getReactInstanceManager(),
appKey,
getLaunchOptions());
// getPlainActivity().setContentView(mReactRootView);
}
protectedvoidonPause() {
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onHostPause(getPlainActivity());
}
}
protectedvoidonResume() {
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onHostResume(
getPlainActivity(),
(DefaultHardwareBackBtnHandler) getPlainActivity());
}
if (mPermissionsCallback != null) {
mPermissionsCallback.invoke();
mPermissionsCallback = null;
}
}
protectedvoidonDestroy() {
if (mReactRootView != null) {
mReactRootView.unmountReactApplication();
mReactRootView = null;
}
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onHostDestroy(getPlainActivity());
}
}
publicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager()
.onActivityResult(getPlainActivity(), requestCode, resultCode, data);
} else {
// Did we request overlay permissions?if (requestCode == REQUEST_OVERLAY_PERMISSION_CODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Settings.canDrawOverlays(getContext())) {
if (mMainComponentName != null) {
loadApp(mMainComponentName);
}
Toast.makeText(getContext(), REDBOX_PERMISSION_GRANTED_MESSAGE, Toast.LENGTH_LONG).show();
}
}
}
}
publicbooleanonKeyUp(int keyCode, KeyEvent event) {
if (getReactNativeHost().hasInstance() && getReactNativeHost().getUseDeveloperSupport()) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
getReactNativeHost().getReactInstanceManager().showDevOptionsDialog();
returntrue;
}
boolean didDoubleTapR = Assertions.assertNotNull(mDoubleTapReloadRecognizer)
.didDoubleTapR(keyCode, getPlainActivity().getCurrentFocus());
if (didDoubleTapR) {
getReactNativeHost().getReactInstanceManager().getDevSupportManager().handleReloadJS();
returntrue;
}
}
returnfalse;
}
publicbooleanonBackPressed() {
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onBackPressed();
returntrue;
}
returnfalse;
}
publicbooleanonNewIntent(Intent intent) {
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onNewIntent(intent);
returntrue;
}
returnfalse;
}
@TargetApi(Build.VERSION_CODES.M)
publicvoidrequestPermissions(
String[] permissions,
int requestCode,
PermissionListener listener) {
mPermissionListener = listener;
getPlainActivity().requestPermissions(permissions, requestCode);
}
publicvoidonRequestPermissionsResult(
finalint requestCode,
final String[] permissions,
finalint[] grantResults) {
mPermissionsCallback = new Callback() {
@Overridepublicvoidinvoke(Object... args) {
if (mPermissionListener != null && mPermissionListener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
mPermissionListener = null;
}
}
};
}
private Context getContext() {
if (mActivity != null) {
return mActivity;
}
return Assertions.assertNotNull(mFragmentActivity);
}
private Activity getPlainActivity() {
return ((Activity) getContext());
}
public ReactRootView getRootView() {
return mReactRootView;
}
}
MainActivity.java
package com.example;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import java.util.LinkedList;
import java.util.List;
publicclassMainActivityextendsMyReactActivityimplementsMyFragmentDelegate {private ReactFragment reactFragment;
private List fragments = new LinkedList<>();
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/@Overrideprotected String getMainComponentName() {
return"Example";
}
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (reactFragment == null) {
reactFragment = new ReactFragment();
reactFragment.setRootView(getRootView());
}
push(reactFragment, "ReactFragment");
}
@Overridepublicvoidpush(Fragment fragment, String tag) {
getSupportFragmentManager().beginTransaction().add(R.id.id_main_container, fragment, tag).commit();
}
@Overridepublicvoidpop() {
List fragments = getSupportFragmentManager().getFragments();
getSupportFragmentManager().beginTransaction().remove(fragments.get(fragments.size()-1)).commit();
}
@OverridepublicvoidstartRN(String params) {
List fragments = getSupportFragmentManager().getFragments();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
for (Fragment fragment : fragments) {
if (fragment instanceof ReactFragment) {
fragmentTransaction.show(fragment);
} else {
fragmentTransaction.hide(fragment);
}
}
fragmentTransaction.commit();
RouterModule.startReactPage("login");
}
@OverridepublicvoidreactBack() {
List fragments = getSupportFragmentManager().getFragments();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
for (Fragment fragment : fragments) {
fragmentTransaction.show(fragment);
}
fragmentTransaction.commit();
}
}
MyFragmentDelegate.java:
package com.example;
import android.support.v4.app.Fragment;
/**
* Created by yinqingyang on 2018/5/6.
*/publicinterfaceMyFragmentDelegate {void push(Fragment fragment,String tag);
void pop();
void startRN(String params);
void reactBack();
}
现实生活中,有些工作是需要团队中成员依次完成的,这就涉及到了一个顺序问题。现在有T1、T2、T3三个工人,如何保证T2在T1执行完后执行,T3在T2执行完后执行?问题分析:首先问题中有三个实体,T1、T2、T3, 因为是多线程编程,所以都要设计成线程类。关键是怎么保证线程能依次执行完呢?
Java实现过程如下:
public class T1 implements Runnabl
hive在使用having count()是,不支持去重计数
hive (default)> select imei from t_test_phonenum where ds=20150701 group by imei having count(distinct phone_num)>1 limit 10;
FAILED: SemanticExcep
转载源:http://blog.sina.com.cn/s/blog_4f925fc30100rx5l.html
mysql -uroot -p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@centos var]# service mysql
#mq
xdr.mq.url=tcp://192.168.100.15:61618;
import java.io.IOException;
import java.util.Properties;
public class Test {
String conf = "log4j.properties";
private static final
有一个工程,本来运行是正常的,我想把它移植到另一台PC上,结果报:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mobovip.bgr/com.mobovip.bgr.MainActivity}: java.lang.ClassNotFoundException: Didn't f
// 报错如下:
$ git pull origin master
fatal: unable to access 'https://git.xxx.com/': SSL certificate problem: unable to get local issuer ce
rtificate
// 原因:
由于git最新版默认使用ssl安全验证,但是我们是使用的git未设