提交 a44ff91d 编写于 作者: T Takeya Yuki

Add Restful API Client

上级 330d7dbe
...@@ -3,6 +3,24 @@ ...@@ -3,6 +3,24 @@
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<entry_points version="2.0" /> <entry_points version="2.0" />
</component> </component>
<component name="JavadocGenerationManager">
<option name="OUTPUT_DIRECTORY" value="B:/" />
<option name="OPTION_SCOPE" value="protected" />
<option name="OPTION_HIERARCHY" value="true" />
<option name="OPTION_NAVIGATOR" value="true" />
<option name="OPTION_INDEX" value="true" />
<option name="OPTION_SEPARATE_INDEX" value="true" />
<option name="OPTION_DOCUMENT_TAG_USE" value="false" />
<option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false" />
<option name="OPTION_DOCUMENT_TAG_VERSION" value="false" />
<option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true" />
<option name="OPTION_DEPRECATED_LIST" value="true" />
<option name="OTHER_OPTIONS" value="encoding=UTF-8" />
<option name="HEAP_SIZE" />
<option name="LOCALE" />
<option name="OPEN_IN_BROWSER" value="true" />
<option name="OPTION_INCLUDE_LIBS" value="false" />
</component>
<component name="NullableNotNullManager"> <component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" /> <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" /> <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".MainActivity"> <activity android:name=".MainActivity" android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>
...@@ -23,5 +23,5 @@ ...@@ -23,5 +23,5 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_STORAGE"/> <uses-permission android:name="android.permission.READ_MEDIA_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE"/> <uses-permission android:name="android.permission.INTERNET"/>
</manifest> </manifest>
\ No newline at end of file
package jp.ruby.rubylibrary;
/**
* Created by Akeno on 2017/06/30.
*/
public class A {
public int a;
public String b;
}
package jp.ruby.rubylibrary; package jp.ruby.rubylibrary;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import yuki.control.extended.WebViewEx;
import yuki.resource.extended.GsonConvert;
import yuki.resource.extended.StorageIOManager; import yuki.resource.extended.StorageIOManager;
import yuki.resource.extended.UIController; import yuki.resource.extended.UIController;
...@@ -16,26 +28,17 @@ public class MainActivity extends Activity { ...@@ -16,26 +28,17 @@ public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
TextView tv=(TextView)findViewById(R.id.tv); A a=new A();
String s= null; a.a=1;
UIController.SetStatusBarBackgroundColor(this,Color.BLACK); a.b="hello world!";
UIController.SetNavigationBarBackgroundColor(this,Color.RED); TextView tv=findViewById(R.id.tv);
//UIController.HideStatusBar(this); String gson=GsonConvert.SerializeObject(a);
UIController.HideNavigationBar(this); tv.setText(gson);
//UIController.ShowStatusBar(this); A b=GsonConvert.DeserializeObject(gson,A.class);
UIController.ShowNavigationBar(this); b=null;
try { Intent aa=new Intent(Intent.ACTION_VIEW, Uri.parse("weixin://baidu.com/"));
s=String.format("Screen Size\nReal Size: %d px * %d px\n", UIController.GetRealDisplayWidth(this),UIController.GetRealDisplayHeight(this)); startActivity(aa);
s+=String.format("Real Size: %d dp * %d dp\n", UIController.PixelToDP(UIController.GetRealDisplayWidth(this),UIController.GetRealDisplayMetrics(this).density),
UIController.PixelToDP(UIController.GetRealDisplayHeight(this),UIController.GetRealDisplayMetrics(this).density));
s+=String.format("Logical Size: %d px * %d px\n", UIController.GetLogicalDisplayWidth(this),UIController.GetLogicalDisplayHeight(this));
s+=String.format("Logical Size: %d dp * %d dp\n", UIController.PixelToDP(UIController.GetLogicalDisplayWidth(this),UIController.GetLogicalDisplayMetrics(this).density),
UIController.PixelToDP(UIController.GetLogicalDisplayHeight(this),UIController.GetLogicalDisplayMetrics(this).density));
tv.setText(s);
} catch (Exception e) {
e.printStackTrace();
tv.setText(e.getLocalizedMessage());
}
} }
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
tools:context="jp.ruby.rubylibrary.MainActivity"> tools:context="jp.ruby.rubylibrary.MainActivity">
<TextView <TextView
android:id="@+id/tv" android:id="@+id/tv"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="TextView" android:text="TextView" />
tools:layout_editor_absoluteX="3dp" </LinearLayout>
tools:layout_editor_absoluteY="2dp" />
</android.support.constraint.ConstraintLayout>
...@@ -6,7 +6,7 @@ buildscript { ...@@ -6,7 +6,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.novoda:bintray-release:0.3.4'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }
...@@ -18,6 +18,13 @@ allprojects { ...@@ -18,6 +18,13 @@ allprojects {
} }
} }
subprojects {
tasks.withType(Javadoc).all { enabled = false }
}
task clean(type: Delete) { task clean(type: Delete) {
delete rootProject.buildDir delete rootProject.buildDir
} }
gradlew clean build bintrayUpload -PbintrayUser=takeya-yuki -PbintrayKey=%1 -PdryRun=%2 %3
\ No newline at end of file
# Project-wide Gradle settings. ## Project-wide Gradle settings.
#
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit # For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html # http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process. # Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings. # The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m # Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode. # When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit # This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
#Thu Jun 29 16:11:36 CST 2017
#systemProp.http.proxyHost=127.0.0.1
org.gradle.jvmargs=-Xmx1536m
#systemProp.http.proxyPort=1080
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
publish {
userOrg = 'takeya-yuki-studio' //bintray注册的用户名
groupId = 'jp.ruby.rubylib' //compile引用时的第1部分groupId
artifactId = 'rubylib' //compile引用时的第2部分项目名
publishVersion = '1.0.3' //compile引用时的第3部分版本号
desc = 'Ruby Extended Controls'
website = 'https://github.com/Takeya-Yuki/RubyLib.git'
}
android { android {
compileSdkVersion 26 compileSdkVersion 26
...@@ -7,8 +20,8 @@ android { ...@@ -7,8 +20,8 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 17 minSdkVersion 17
targetSdkVersion 26 targetSdkVersion 26
versionCode 1 versionCode 3
versionName "1.0" versionName "1.0.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
...@@ -23,6 +36,7 @@ android { ...@@ -23,6 +36,7 @@ android {
versionNameSuffix '1.0' versionNameSuffix '1.0'
} }
} }
} }
dependencies { dependencies {
...@@ -31,5 +45,6 @@ dependencies { ...@@ -31,5 +45,6 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })
compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support:appcompat-v7:26.+'
compile 'com.google.code.gson:gson:2.8.1'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }
...@@ -6,5 +6,6 @@ ...@@ -6,5 +6,6 @@
android:supportsRtl="true"> android:supportsRtl="true">
</application> </application>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
</manifest> </manifest>
...@@ -237,4 +237,46 @@ public final class HttpAsyncClient { ...@@ -237,4 +237,46 @@ public final class HttpAsyncClient {
} }
}).start(); }).start();
} }
public static void AsyncRESTString(final String Url,final Activity activity,final String RESTMethod,final String ContentType,final String rawData,final OnREST post){
new Thread(new Runnable() {
@Override
public void run() {
HttpURLConnection urlConnection = null;
try {
URL url = new URL(Url);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setRequestMethod(RESTMethod);
urlConnection.setRequestProperty("Content-Type",ContentType);
urlConnection.setRequestProperty("Connection","Keep-Alive");
urlConnection.setRequestProperty("Charset", "UTF-8");
urlConnection.setUseCaches(false);
OutputStream out=urlConnection.getOutputStream();
out.write(rawData.getBytes("UTF-8"));
out.flush();
out.close();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
final String result = readInStream(in);
if (post != null && activity != null && post instanceof OnRESTString) {
activity.runOnUiThread(
new Runnable() {
@Override
public void run() {
((OnRESTString) post).REST(result);
}
}
);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
urlConnection.disconnect();
}
}
}).start();
}
} }
package yuki.control.extended;
/**
* Created by Akeno on 2017/08/04.
*/
public interface OnREST {
}
package yuki.control.extended;
/**
* Created by Akeno on 2017/08/04.
*/
public interface OnRESTString extends OnREST {
public void REST(String data);
}
...@@ -350,6 +350,9 @@ public class WebViewEx extends WebView { ...@@ -350,6 +350,9 @@ public class WebViewEx extends WebView {
@SuppressLint({"SetJavaScriptEnabled"}) @SuppressLint({"SetJavaScriptEnabled"})
protected void init(Context context) { protected void init(Context context) {
if(isInEditMode()){
return;
}
if (context instanceof Activity) { if (context instanceof Activity) {
mActivity = new WeakReference<Activity>((Activity) context); mActivity = new WeakReference<Activity>((Activity) context);
} }
......
...@@ -98,7 +98,13 @@ public class YukiJSBridge { ...@@ -98,7 +98,13 @@ public class YukiJSBridge {
criteria.setCostAllowed(true); criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_HIGH); criteria.setPowerRequirement(Criteria.POWER_HIGH);
Location location = locationManager.getLastKnownLocation(provider); try {
return location; Location location = locationManager.getLastKnownLocation(provider);
return location;
}
catch (SecurityException ex){
//DO NOTHING
return null;
}
} }
} }
...@@ -73,7 +73,7 @@ public class NetworkManager { ...@@ -73,7 +73,7 @@ public class NetworkManager {
public static int GetNetworkType(Context context) { public static int GetNetworkType(Context context) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null || mNetworkInfo.isAvailable()) { if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
if (mNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || mNetworkInfo.getType() == ConnectivityManager.TYPE_WIMAX) { if (mNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || mNetworkInfo.getType() == ConnectivityManager.TYPE_WIMAX) {
return WIFI; return WIFI;
} else { } else {
......
package yuki.resource.extended;
import com.google.gson.Gson;
import java.lang.reflect.Type;
/**
* Created by Akeno on 2017/06/30.
*/
public class GsonConvert {
public static String SerializeObject(Object object){
Gson gson=new Gson();
return gson.toJson(object);
}
public static <T> T DeserializeObject(String gson,Class<T> TClass){
Gson g=new Gson();
return (T)g.fromJson(gson, TClass);
}
}
...@@ -125,4 +125,24 @@ public class UIController { ...@@ -125,4 +125,24 @@ public class UIController {
uiv&=~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; uiv&=~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mDecorView.setSystemUiVisibility(uiv); mDecorView.setSystemUiVisibility(uiv);
} }
public static int GetStatusBarHeight(Activity activity){
int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
if(resourceId>0){
return activity.getResources().getDimensionPixelSize(resourceId);
}
else{
return 0;
}
}
public static int GetNavigationBarHeight(Activity activity){
int resourceId = activity.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if(resourceId>0){
return activity.getResources().getDimensionPixelSize(resourceId);
}
else{
return 0;
}
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册