Browse Source

修改openUrl接口

zhanglong7 7 years ago
parent
commit
45fc251518
1 changed files with 20 additions and 27 deletions
  1. 20 27
      ipu-plugin-basic/src/main/java/com/ai/ipu/mobile/plugin/MobileUI.java

+ 20 - 27
ipu-plugin-basic/src/main/java/com/ai/ipu/mobile/plugin/MobileUI.java

@ -9,6 +9,7 @@ import java.util.Date;
9 9
import java.util.Map;
10 10

11 11
import org.json.JSONArray;
12
import org.json.JSONException;
12 13

13 14
import android.app.AlertDialog;
14 15
import android.app.AlertDialog.Builder;
@ -86,43 +87,35 @@ public class MobileUI extends Plugin {
86 87
	}
87 88
	
88 89
	public void openUrl(JSONArray param) throws Exception{
89
	    Intent intent = new Intent();
90 90
        String url = param.getString(0);
91 91
        String title = param.getString(1);
92
        JSONArray arrayStyles = param.getJSONArray(2);
92
        JSONArray buttons = param.getJSONArray(2);
93
        JSONArray arrayStyles = param.getJSONArray(3);
94
        openUrl(url, title, buttons, arrayStyles);
95
        
96
	}
97
	
98
	private void openUrl(String url, String title, JSONArray buttons, JSONArray arrayStyles) throws Exception {
99
        String[] styleNames = {"topbarbg", "iconcolor", "textcolor"};
100
        String[] buttonNames = {"share", "search", "copyLink"};
101
        url = URLDecoder.decode(url);
102
	    Intent intent = new Intent();
93 103
        intent.putExtra("url", url);
94 104
        intent.putExtra("title", title);
95
//      ArrayList<String> styles = new ArrayList<String>();
105
        
96 106
        for(int i=0;i< arrayStyles.length();i++){
97
            switch (i) {
98
            case 0:
99
                intent.putExtra("topbarbg", isNull(arrayStyles.getString(0)) ? "" : arrayStyles.getString(0));
100
                break;
101
            case 1:
102
                intent.putExtra("textcolor", isNull(arrayStyles.getString(1)) ? "" : arrayStyles.getString(1));
103
                break;  
107
            if (i < styleNames.length) {
108
                intent.putExtra(styleNames[i], isNull(arrayStyles.getString(i)) ? "" : arrayStyles.getString(i));
104 109
            }
105 110
        }
106
        JSONArray arrayButtons = param.getJSONArray(3);
107
        ArrayList<String> buttons = new ArrayList<String>();
108
        for(int i=0;i< arrayButtons.length();i++){
109
            buttons.add(arrayButtons.getString(i));
111
        for(int i=0; i<buttons.length(); i++) {
112
            if(i < buttonNames.length) {
113
                intent.putExtra(buttonNames[i], buttons.getBoolean(i));
114
            }
110 115
        }
111
        intent.putExtra("buttons", buttons);
112
        String shareContent = param.getString(4);
113
        IData shareData = new DataMap(shareContent);
114
        intent.putExtra("shareData", shareData);
115 116
        intent.setClassName(context, "com.ai.ipu.mobile.ui.activity.IpuUrlActivity");
116 117
        startActivityForResult(intent, REQUEST_CODE_OPEN_URL);
117
	}
118
	
119
	public void openUrl(String url) throws Exception{
120
		url = URLDecoder.decode(url);
121
		Intent intent = new Intent();
122
		intent.setClassName(context, "com.ai.ipu.mobile.ui.activity.OpenUrlActivity");
123
		intent.putExtra("url", url);
124
		startActivityForResult(intent, REQUEST_CODE_OPEN_URL);
125
	}
118
    }
126 119
	
127 120
	public void openPage(JSONArray param) throws Exception {
128 121
		String pageAction = param.getString(0);