当前位置: 首页 > 软件库 > 手机/移动开发 > >

Android-Shortify

授权协议 Apache-2.0 License
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 仲孙信瑞
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Shortify for Android

Shortify is used for minimizing your coding effort in your development environment. It has some builtin method and classes which helps you in creating mostly used element and tasks in Android app.

Download

Grab library via Gradle

compile 'net.dhruvpatel:shortify:1.2.4'

or Maven

<dependency>
  <groupId>net.dhruvpatel</groupId>
  <artifactId>shortify</artifactId>
  <version>1.2.4</version>
  <type>pom</type>
</dependency>

Features

How to use

Initialize library before using it in onCreate method

$.init(this);

Binding of any views

// Basic 
EditText editText = (EditText) context.findViewById(R.id.editText1);
com.example.view.CustomView customView = (com.example.view.CustomView) context.findViewById(R.id.view);

// Shortify
EditText editText = $.bind(R.id.editText1);
com.example.view.CustomView customView = $.bind(R.id.view);

Binding of resources

// Basic 
String str = getApplicationContext().getString(R.string.app_name);
Drawable drawable = getApplicationContext().getDrawable(R.drawable.example);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animation1);

// Shortify
String str           = $.bindString(R.string.app_name);
Drawable drawable    = $.bindDrawable(R.drawable.example);
Animation animation  = $.bindAnimation(R.anim.animation1);
.
.
.
//List of binders
$.bindString(R.string.example);
$.bindDimension(R.dimen.example);
$.bindAnimation(R.anim.example);
$.bindDrawable(R.drawable.example);
$.bindColor(R.color.example);
$.bindInteger(R.integer.example);
$.bindBoolean(R.bool.example);

Customize views

//Basic
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(getApplicationContext().getString(R.string.app_name));
textView.setTextColor(Color.BLUE);
textView.setTextSize(16f);
textView.setAllCaps(true);
Linkify.addLinks(textView, Linkify.ALL);

//Shortify
$.id(R.id.textView).text(R.string.app_name)
   .color(Color.BLUE)
   .size(16)
   .allcapital()
   .linkify();

Parsing JSON data

Shortify can parse long and complex JSON data in simplest way. You can parse any type of data like integer, long, double, boolean, String

int value = $.getIntFromJSON(path, JSON_STRING);
String str = $.getStringFromJSON(path, JSON_STRING);
long value = $.getLongFromJSON(path, JSON_STRING);
double value = $.getDoubleFromJSON(path, JSON_STRING);;
boolean value = $.getBooleanFromJSON(path, JSON_STRING);

Example 1

{
     "$schema": "http://json-schema.org/draft-04/schema#",
     "title": "Product",
     "description": "A product from Acme's catalog",
     "type": "object",
     "properties": {
         "id": {
             "description": "The unique identifier for a product",
             "type": "integer"
         },
         "name": {
             "description": "Name of the product",
             "type": "string"
         },
         "price": {
             "type": "number",
             "minimum": 0,
             "exclusiveMinimum": true
         },
         "tags": {
             "type": "array",
             "items": {
                 "type": "string"
             },
             "minItems": 1,
             "uniqueItems": true
         }
     },
     "required": ["id", "name", "price"]
 }
  1. Now suppose we want to get value of properties > price > minimum
int value = $.getStringFromJSON("properties.price.minimum", JSON_STRING);
  1. Suppose we want to get value of properties > tags > items > type
String value = $.getStringFromJSON("properties.tags.items.type", JSON_STRING);
  1. If we want to get 2nd element of required object
String value = $.getStringFromJSON("required[1]", JSON_STRING);

Example 2

This example has array of user and no object is assigned to whole array

[
  {
    "name":{
      "first": "first name 1",
      "last": "last name 1"
    },
    "dob":{
      "month": "January",
      "day": 1
    }
  },
  {
    "name":{
      "first": "first name 2",
      "last": "last name 2"
    },
    "dob":{
      "month": "May",
      "day": 2
    }
  }
]

Now suppose we want to get value of 1st user's first name

String name = $.getStringFromJSON("[0].name.first", JSON_STRING);

AJAX

Shortify enables you to send AJAX request to server via both GET and POST method and it can also retrive response from webpage

GET method

$.httpGet("http://example.com/rest/api", new AJAX.AJAXCallback() {
   @Override
   public void onComplete(String response) {
       Log.d(TAG, response);
   }
});

POST method

HashMap<String, Object> queryStringData = new HashMap<>();
queryStringData.put("name","Dhruv");
queryStringData.put("age",22);
queryStringData.put("auth",true);

$.httpPost("http://example.com/rest/api",queryStringData,  new AJAX.AJAXCallback() {
   @Override
   public void onComplete(String response) {
       Log.d(TAG, response);
   }
});

Event handlers

//Basic
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        ...
    }
});
   
//Shortify     
$.id(R.id.button).click(new Task() {
    @Override
    public void perform() {
        ...
    }
});

Dialogs

//Simple alert dialog box
$.alertDialog("Title","Description");

//Generates and shows dialog with OK button with onClick event handlers
$.confirmDialog("Title", "Description", new Click() {
    @Override
    public void ok() {
                
    }
});

//Generates and shows dialog with YES and NO button with onClick event handlers
$.yesNoDialog("Title", "Description", new Agree() {
    @Override
    public void yes() {
            
    }

    @Override
    public void no() {

    }
});

Other functions

//Check, if app is installed or not in device 
$.checkIfAppInstalled(PKG_NAME);

//Open current or any other app page in Play store app
$.openAppInStore();
$.openAppInStore(PKG_NAME);

//Showing toast
$.toast(MESSAGE);

//Get current date and time in any format
$.time("d m y");

//Check app permission (used for Runntime Permission Model)
$.checkPermission(PERMISSION_STRING);

//Navigate to any activity with or without passing data
$.open(Activity.class);
$.open(Activity.class, bundle);

Apps using Shortify for Android

Apps
Slefie Flashlight Selfie Flashlight
Material Music Player Material Music Player

Ping me for adding your app in this list

Thanks for using. if you have any suggestions or bug report please create new issue here

 相关资料
  • JNI绑定 Android上的Java资源 WebView代码组织

  • Native.js for Android封装一条通过JS语法直接调用Native Java接口通道,通过plus.android可调用几乎所有的系统API。 方法: currentWebview: 获取当前Webview窗口对象的native层实例对象 newObject: 创建实例对象 getAttribute: 获取对象(类对象/实例对象)的属性值 setAttribute: 设置对象(类对

  • Android++ 是一个免费的 Visual Studio 扩展,用于支持在 Visual Studio 上开发和调试原生的 Android 应用,主要基于 NDK 的 C/C++ 应用。同时包括可订制的发布、资源管理以及集成了 Java 源码编译。

  • Android(安卓)是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国谷歌公司和开放手机联盟领导及开发。Android操作系统最初由Andy Rubin开发,主要支持手机。2005年8月由谷歌收购注资。2007年11月,谷歌与84家硬件制造商、软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统。随后谷歌以Apache许可证的授

  • Android(安卓)是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国谷歌公司和开放手机联盟领导及开发。Android操作系统最初由Andy Rubin开发,主要支持手机。2005年8月由谷歌收购注资。2007年11月,谷歌与84家硬件制造商、软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统。随后谷歌以Apache许可证的授

  • 简介 该库提供J2SE的Swing、AWT等类的安卓实现,引用该库便能在Android上运行J2SE应用程序。 该库实现大多数必需功能,但不是全部的J2SE。 成功示例HomeCenter服务器,该服务器基于J2SE,同时完全运行于Android之上。 使用指引 该库依赖于开源工程HomeCenter。 它不含Activity,需另建Android工程,并引用本库。 Activity和res需作为